#include<stdio.h>
#include<string.h>
#include<math.h>



int main()
{
    int a,h,m,s;
    int intime,nowtime;    
    int nowh,nowm,nows;
    
    int i;
    
    while(1)
    {
        scanf("%d",&a);
        if(a<0) break;
        
        scanf("%d:%d:%d",&h,&m,&s);
        
        intime=3600*h+60*m+s;
        
        i=h-1;
        while(1)
        {
            i++;  if(i>23) i-=24;
            
            if(i>=12)
                nowh=i-12;
            else
                nowh=i;

            nowm=int( (a+30*nowh)*2.0/11.0 );
            nows=int( (a+30*nowh-nowm*11.0/2.0)*120.0/11.0 );
            if(nowm>=60 || nows>=60 || nowm<0 || nows<0)
            {
                nowm=int( (a+30*nowh-360.0)*2.0/11.0 );
                nows=int( (a+30*nowh-nowm*11.0/2.0-360.0)*120.0/11.0 );
                if(nowm>=60 || nows>=60 || nowm<0 || nows<0)
                {
                    continue;
                }
				else
				{
					nowtime=3600*i+60*nowm+nows;
					if(nowtime>=intime || i!=h)
					{
						break;
					}
				}
            }  
			else
			{
				nowtime=3600*i+60*nowm+nows;
				if(nowtime>=intime || i!=h)
				{
					break;
				}
			}
        } 
        
        printf("%02d:%02d:%02d\n",i,nowm,nows);
    }    
    return 0;
}    


